<?php

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

$list = array();
$url = $_SC['apiurl'];
$mpurl = 'admin.php?ac=topic';
$tid = intval($_GET['tid']);
$rate_min = 10;
$rate_max = 15;
$res_num = 0;
$view_num = 0;

if ($_GET ['op'] == "correctTopic"){
     $topicInfo    =    getAdminTopicInfo($url, $tid);
     if ($topicInfo) {
         $orgin_view_num = $topicInfo['view_num'];
         $orgin_res_num = $topicInfo['res_num'];
     }

     $orgin_res_num = $orgin_res_num ? $orgin_res_num : 1;
     $orgin_view_num = $orgin_view_num ? $orgin_view_num : 1;
     // 倍率校正
     $rate = rand(10, 15);
     $view_num = $rate * $orgin_res_num;

     $result  =   correctAdminTopicCount($url, $tid, $view_num);
     if ($result) {
        echo 1;
     }else{
        echo 0;
     }
     exit;
     
}else {
    $topicInfo = array();
    if ($tid) {
        $topicInfo    =    getAdminTopicInfo($url, $tid);
    }
}

// 获取话题详情
function getAdminTopicInfo($url, $tid){
    $param = array(
        'do'          =>    'getAdminTopicInfo',
        'format'      =>    'json',
        'tid'         =>    $tid
    );

    $topicInfo 		=  	requestAndResponse($url, $param);
// echo '<pre>';var_dump($topicInfo);exit;
    $result			=	$topicInfo['topic_info'];
    return $result;
}

// 校正话题计数
function correctAdminTopicCount($url, $tid, $view_num){
    $param = array(
        'do'          =>    'correctAdminTopicCount',
        'format'      =>    'json',
        'tid'         =>    $tid,
        'view_num'    =>    $view_num
    );

    $result 		=  	requestAndResponse($url, $param);
    return $result;
}




